package com.my.jli.util;

import com.my.jli.entity.Student;

import java.util.*;

/**
 * @ClassName SignCodeUtil
 * @Description 签到工具类
 * @Author MaYu
 * @Date 2022/3/24 14:46
 * @Version 1.0
 **/
public class SignCodeUtil {
    //验证码
    private String code;
    //生效时间
    private Long startDate;
    //失效时间
    private Long endDate;
    //已经签到的学生列表
    private Set<Student> signStu;

    public SignCodeUtil() {
        Random random = new Random();
        int i = random.nextInt(900000) + 100000;//生成随机数做验证码
        this.code = String.valueOf(i);

        this.startDate = new Date().getTime();//获取当前时间
        this.endDate = startDate + 120000;

        this.signStu = new HashSet<>();
    }

    public SignCodeUtil resetCode(){
        Random random = new Random();
        int i = random.nextInt(900000) + 100000;//生成随机数做验证码
        this.code = String.valueOf(i);
        return this;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getStartDate() {
        return startDate;
    }

    public void setStartDate(Long startDate) {
        this.startDate = startDate;
    }

    public Long getEndDate() {
        return endDate;
    }

    public void setEndDate(Long endDate) {
        this.endDate = endDate;
    }

    public Set<Student> getSignStu() {
        return signStu;
    }

    public void setSignStu(Set<Student> signStu) {
        this.signStu = signStu;
    }

    @Override
    public String toString() {
        return "SignCodeUtil{" +
                "code='" + code + '\'' +
                ", startDate=" + startDate +
                ", endDate=" + endDate +
                ", noSignStu=" + signStu +
                '}';
    }
}
